package ch03.jdkProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author Jane
 * @date 2024-03-25 16:29
 */

public class BuyInvocationHandler implements InvocationHandler {
    private Object buyer;

   public BuyInvocationHandler( Object buyer){
       this.buyer = buyer;
   }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        before();
        Object obj = method.invoke(buyer, args);
        System.out.println(obj);
        after();
        return obj;
    }
    public void before(){
        System.out.println("买之前先货比三家");
    }
    public void after(){
        System.out.println("早买早享受");
    }
}
